package com.hgnu.dorm.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.util.SaResult;
import com.hgnu.dorm.domain.dto.BuildingPageQueryDto;
import com.hgnu.dorm.domain.po.Building;
import com.hgnu.dorm.domain.po.PageBean;
import com.hgnu.dorm.domain.po.Result;
import com.hgnu.dorm.service.BuildingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/buildings")
@Slf4j
@Tag(name = "楼宇管理接口")
public class BuildingController {
    @Autowired
    private BuildingService buildingService;
    //分页查询
    @GetMapping
    @Operation(summary = "获取楼宇列表接口")
    @SaCheckPermission("build.select")
    public SaResult list(BuildingPageQueryDto dto){
        PageBean page = buildingService.page(dto);
        return SaResult.data(page);
    }
    //新增楼宇
    @PostMapping
    @Operation(summary = "新增楼宇接口")
    @SaCheckPermission("build.add")
    public SaResult add(@RequestBody Building building){
        buildingService.insertBuilding(building);
        return SaResult.ok();
    }
    //修改楼宇
    @PutMapping
    @Operation(summary = "修改楼宇接口")
    @SaCheckPermission("build.update")
    public SaResult update(@RequestBody Building building){
        buildingService.updateBuilding(building);
        return SaResult.ok();
    }
    //删除楼宇
    @DeleteMapping("/{ids}")
    @Operation(summary = "根据多个id删除楼宇")
    @SaCheckPermission("build.delete")
    public SaResult delete(@PathVariable("ids") Long[] ids){
        buildingService.deleteBuilding(ids);
        return SaResult.ok();
    }
    //根据id查询楼宇
    @GetMapping("/{id}")
    @Operation(summary = "根据id获取单个楼宇")
    @SaCheckPermission("build.select")
    public SaResult get(@PathVariable("id") Integer id){
        Building building = buildingService.getById(id);
        return SaResult.data(building);
    }

}
